﻿using Modules;
using PmSoft;
using System.Security.Authentication;

namespace ManagementApi.Mvc.ApplicationContexts;

/// <summary>
/// 项目管理员请求上下文
/// </summary>
[UseDI(ServiceLifetime.Scoped)]
public class ProjectManagerApplicationContext : ProjectUserApplicationContext
{
    public ProjectManagerApplicationContext(IServiceProvider serviceProvider) : base(serviceProvider)
    {
    }


    private ManagerInfo? _managerInfo = null;

    /// <summary>
    /// 当前登录的项目管理员（劳务员）信息
    /// </summary>
    public ManagerInfo CurrentManager
    {
        get
        {
            if (_managerInfo != null)
                return (ManagerInfo)_managerInfo;

            if (CurrentUser == null || CurrentUser is not ManagerInfo managerInfo)
                throw new AuthenticationException("当前非项目管理员用户类型");
            _managerInfo = managerInfo;
            return _managerInfo;
        }
    }

}
